// Author: wsfuyibing <682805@qq.com>
// Date: 2025-03-28

package config

import "gitee.com/go-libs/config"

const (
	DefaultAppPort    = 8080
	DefaultAppName    = "gin"
	DefaultAppVersion = "0.0.0"
)

// AppConfig
// Gin应用配置.
//
//	framework.Application.AppConfig()
type AppConfig struct {
	Port    int    `yaml:"port" label:"服务端口"`
	Host    string `yaml:"host" label:"服务地址"`
	Name    string `yaml:"name" label:"服务名称"`
	Version string `yaml:"version" label:"服务版本"`
}

// After 后置钩子, 从yaml配置文件加载后执行.
func (o *AppConfig) After() {
	if o.Port == 0 {
		o.Port = DefaultAppPort
	}
	if o.Name == "" {
		o.Name = DefaultAppName
	}
	if o.Version == "" {
		o.Version = DefaultAppVersion
	}
}

// Load 从yaml配置文件加载配置参数.
func (o *AppConfig) Load() *AppConfig {
	_ = config.Seek("app.yaml", "app.yml").ScanYaml(o)
	return o
}
